package com.ruoyi.web.controller.applet;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.dto.BdmGoodDto;
import com.ruoyi.system.domain.vo.BdmCloudInventoryItemVo;
import com.ruoyi.system.domain.vo.BdmCloudInventoryItemVoList;
import com.ruoyi.system.domain.vo.applet.ProductReviewsVo;
import com.ruoyi.system.domain.vo.applet.AppletBdmGoodVo;
import com.ruoyi.system.domain.vo.applet.AppletBdmUserIntegralGoodVo;
import com.ruoyi.system.service.IBdmGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 会员商品Controller
 * 
 * @author ruoyi
 * @date 2024-12-07
 */
@RestController
@RequestMapping("/applet/good")
@Validated
public class AppletGoodController extends BaseController
{
    @Autowired
    private IBdmGoodService bdmGoodService;


    /**
     * 查询代理商商品列表 返回 名称 描述 销量 喜欢  是否购买过礼包 价格  会员价格
     */
    @GetMapping("/listGoodVo")
    public TableDataInfo listGoodVo(BdmGoodDto bdmGoodDto)
    {
        startPage();
        List<AppletBdmGoodVo> list = bdmGoodService.listGoodVo(bdmGoodDto);
        return getDataTable(list);
    }

    /**
     * 查询代理商商品详情 返回 名称 描述 销量 喜欢  是否购买过礼包 价格  会员价格
     */
    @GetMapping("/GoodVo/{goodId}")
    public AjaxResult goodVo(@PathVariable("goodId") Long goodId)
    {
        AppletBdmGoodVo appletBdmGoodVo = bdmGoodService.goodVo(goodId);
        return success(appletBdmGoodVo);
    }

    /**
     * 查询 积分商城列表
     * @return {@link AppletBdmUserIntegralGoodVo}
     */
    @GetMapping("/integralGoodList")
    public AjaxResult integralGoodList()
    {
        AppletBdmUserIntegralGoodVo appletBdmUserIntegralGoodVo= bdmGoodService.integralGoodList();
        return success(appletBdmUserIntegralGoodVo);
    }

    /**
     * 查询云仓运费
     * @param bdmCloudInventoryItemVoList
     * @return
     */
    @PostMapping("/getCostPrice")
    public AjaxResult getCostPrice(@RequestBody BdmCloudInventoryItemVoList bdmCloudInventoryItemVoList) {
        return bdmGoodService.getCostPrice(bdmCloudInventoryItemVoList);
    }

    /**
     * 查询商品评论
     * @return {@link ProductReviewsVo}
     */
    @GetMapping("/productReviews")
    public TableDataInfo productReviews(@Valid @NotNull(message = "商品id是必填的") Long goodId)
    {
        startPage();
        List<ProductReviewsVo> list = bdmGoodService.productReviews(goodId);
        return getDataTable(list);
    }

    /**
     * 获取商品二维码
     * @param goodId 商品id
     * @return {@link AjaxResult}
     * @throws Exception
     */
    @GetMapping("/getGoodQrCode/{goodId}/{userId}")
    public AjaxResult getGoodQrCode(@Valid @NotNull(message = "商品id是必填的") @PathVariable Long goodId , @PathVariable("userId") Long userId) throws Exception {
        return bdmGoodService.getGoodQrCode(goodId,userId);
    }

}
